using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Belmost4PDA.Fasade;

namespace Belmost4PDA.Logic
{
    public class Mapper_CheckBox:AbstractMapper
    {
        public Control_CheckBox checkBox = null;

        public Mapper_CheckBox(AbstractControl checkbox)
        {
            checkBox = (Control_CheckBox) checkbox;
            SetValName(((PanelItem)(checkbox.GetFormControl().Tag)).Caption);
        }
        public override void ToControls(DataRows.DataRows row)
        {
            if (row.FieldByNameDef(FieldName(), "") == ((PanelItem)(checkBox.GetFormControl().Tag)).trueVal)
            {
                ((CheckBox)checkBox.GetFormControl()).Checked = true;
                SetInitValue(((PanelItem)(checkBox.GetFormControl().Tag)).trueVal);
            }
            else
            {
                //if (row.FieldByNameDef(FieldName(), "") == ((PanelItem)(checkBox.GetFormControl().Tag)).falseVal)
                //{
                    ((CheckBox) checkBox.GetFormControl()).Checked = false;
                    SetInitValue(((PanelItem) (checkBox.GetFormControl().Tag)).falseVal);
                //}
            }
        }

        public override bool IsKey()
        {
            return false;
        }

        public override string FieldName()
        {
            return ((PanelItem)(checkBox.GetFormControl().Tag)).FieldName;
        }

        public override string FieldVal()
        {
            if(((CheckBox)checkBox.GetFormControl()).Checked) return ((PanelItem)(checkBox.GetFormControl().Tag)).trueVal;
            else return ((PanelItem)(checkBox.GetFormControl().Tag)).falseVal; 
        }
    }
}
